using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ACME.Northwind.DataTransfer;
using ACME.Northwind.Service.Interfaces;
using ACME.Northwind.MockProxy.EventArgs;

namespace ACME.Northwind.MockProxy
{
	/// <summary>
	/// The service implementation for Order object
	/// </summary>
	public partial class OrderService : IOrderService
	{
		#region IOrderService Members

		/// <summary>
		/// Run the mock for the select by the primary key
		/// </summary>
		public OrderDTO SelectByPrimaryKey(int orderid)
		{
			OrderPrimaryKeyEventArgs eventArgs = new OrderPrimaryKeyEventArgs(orderid);
			this.OnMockOrderSelectByPrimaryKey(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Run the mock for select all
		/// </summary>
		public List<OrderDTO> RunSelect()
		{
			OrderRunSelectEventArgs eventArgs = new OrderRunSelectEventArgs();
			this.OnMockOrderRunSelect(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Run the mock for select with LINQ
		/// </summary>
		public List<OrderDTO> RunSelect(string linq)
		{
			OrderRunSelectLINQEventArgs eventArgs = new OrderRunSelectLINQEventArgs(linq);
			this.OnMockOrderRunSelectLINQ(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Run the mock for paged select
		/// </summary>
		public PagedQueryResults<OrderDTO> RunSelect(int pageIndex, int pageSize, bool ascending, string sortColumn, string linq)
		{
			OrderRunSelectPagedEventArgs eventArgs = new OrderRunSelectPagedEventArgs(pageIndex, pageSize, ascending, sortColumn, linq);
			this.OnMockOrderRunSelectPaged(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Return a list of related OrderDetail objects
		/// </summary>
		public List<OrderDetailDTO> GetOrderDetailList(OrderDTO item)
		{
			OrderDTOEventArgs eventArgs = new OrderDTOEventArgs(item);
			this.OnMockGetOrderDetailList(eventArgs);
			List<OrderDetailDTO> retval = new List<OrderDetailDTO>();
			retval.AddRange(eventArgs.ReturnDTOList.Select(x => (OrderDetailDTO)x));
			return retval;
		}

		/// <summary>
		/// Return the related Customer item
		/// </summary>
		public CustomerDTO GetCustomerItem(OrderDTO item)
		{
			CustomerDTO retval = new CustomerDTO();
			OrderDTOEventArgs eventArgs = new OrderDTOEventArgs(item);
			this.OnMockGetCustomerItem(eventArgs);
			retval = (CustomerDTO)eventArgs.ReturnDTOItem;
			return retval;
		}

		/// <summary>
		/// Return the related Employee item
		/// </summary>
		public EmployeeDTO GetEmployeeItem(OrderDTO item)
		{
			EmployeeDTO retval = new EmployeeDTO();
			OrderDTOEventArgs eventArgs = new OrderDTOEventArgs(item);
			this.OnMockGetEmployeeItem(eventArgs);
			retval = (EmployeeDTO)eventArgs.ReturnDTOItem;
			return retval;
		}

		/// <summary>
		/// Return the related Shipper item
		/// </summary>
		public ShipperDTO GetShipperItem(OrderDTO item)
		{
			ShipperDTO retval = new ShipperDTO();
			OrderDTOEventArgs eventArgs = new OrderDTOEventArgs(item);
			this.OnMockGetShipperItem(eventArgs);
			retval = (ShipperDTO)eventArgs.ReturnDTOItem;
			return retval;
		}

		/// <summary>
		/// Persists a single item
		/// </summary>
		public bool Persist(OrderDTO dto)
		{
			OrderPersistEventArgs eventArgs = new OrderPersistEventArgs(dto);
			this.OnMockOrderPersist(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Persists a list
		/// </summary>
		public bool Persist(List<OrderDTO> list)
		{
			OrderPersistEventArgs eventArgs = new OrderPersistEventArgs(list);
			this.OnMockOrderPersist(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Delete a single item
		/// </summary>
		public bool Delete(OrderDTO dto)
		{
			OrderDeleteEventArgs eventArgs = new OrderDeleteEventArgs(dto);
			this.OnMockOrderDelete(eventArgs);
			return eventArgs.ReturnValue;
		}

		#endregion

		#region Order Events

		partial void GetSelectByPrimaryKey();

		/// <summary>
		/// The event for the SelectByPrimaryKey method
		/// </summary>
		public event EventHandler<OrderPrimaryKeyEventArgs> MockOrderSelectByPrimaryKey;

		/// <summary>
		/// Raises the OnMockRegistrationCodeSelectByPrimaryKey event
		/// </summary>
		protected virtual void OnMockOrderSelectByPrimaryKey(OrderPrimaryKeyEventArgs e)
		{
			if (this.MockOrderSelectByPrimaryKey != null)
				this.MockOrderSelectByPrimaryKey(this, e);
		}

		/// <summary>
		/// The event for the RunSelect method
		/// </summary>
		public event EventHandler<OrderRunSelectEventArgs> MockOrderRunSelect;

		/// <summary>
		/// Raises the OnMockRunSelect event
		/// </summary>
		protected virtual void OnMockOrderRunSelect(OrderRunSelectEventArgs e)
		{
			if (this.MockOrderRunSelect != null)
				this.MockOrderRunSelect(this, e);
		}

		/// <summary>
		/// The event for the RunSelectLINQ method
		/// </summary>
		public event EventHandler<OrderRunSelectLINQEventArgs> MockOrderRunSelectLINQ;

		/// <summary>
		/// The event for the OnMockRunSelectLINQ method
		/// </summary>
		protected virtual void OnMockOrderRunSelectLINQ(OrderRunSelectLINQEventArgs e)
		{
			if (this.MockOrderRunSelectLINQ != null)
				this.MockOrderRunSelectLINQ(this, e);
		}

		/// <summary>
		/// The event for the RunSelectPaged method
		/// </summary>
		public event EventHandler<OrderRunSelectPagedEventArgs> MockOrderRunSelectPaged;

		/// <summary>
		/// The event for the OnMockRunSelectPaged method
		/// </summary>
		protected virtual void OnMockOrderRunSelectPaged(OrderRunSelectPagedEventArgs e)
		{
			if (this.MockOrderRunSelectPaged != null)
				this.MockOrderRunSelectPaged(this, e);
		}

		/// <summary>
		/// The event for the GetOrderDetailList method
		/// </summary>
		public event EventHandler<OrderDTOEventArgs> MockGetOrderDetailList;

		/// <summary>
		/// The event for the OnMockGetOrderDetailList method
		/// </summary>
		protected virtual void OnMockGetOrderDetailList(OrderDTOEventArgs e)
		{
			if (this.MockGetOrderDetailList != null)
				this.MockGetOrderDetailList(this, e);
		}

		/// <summary>
		/// The event for the GetCustomerItem method
		/// </summary>
		public event EventHandler<OrderDTOEventArgs> MockGetCustomerItem;

		/// <summary>
		/// The event for the OnMockGetCustomerItem method
		/// </summary>
		protected virtual void OnMockGetCustomerItem(OrderDTOEventArgs e)
		{
			if (this.MockGetCustomerItem != null)
				this.MockGetCustomerItem(this, e);
		}

		/// <summary>
		/// The event for the GetEmployeeItem method
		/// </summary>
		public event EventHandler<OrderDTOEventArgs> MockGetEmployeeItem;

		/// <summary>
		/// The event for the OnMockGetEmployeeItem method
		/// </summary>
		protected virtual void OnMockGetEmployeeItem(OrderDTOEventArgs e)
		{
			if (this.MockGetEmployeeItem != null)
				this.MockGetEmployeeItem(this, e);
		}

		/// <summary>
		/// The event for the GetShipperItem method
		/// </summary>
		public event EventHandler<OrderDTOEventArgs> MockGetShipperItem;

		/// <summary>
		/// The event for the OnMockGetShipperItem method
		/// </summary>
		protected virtual void OnMockGetShipperItem(OrderDTOEventArgs e)
		{
			if (this.MockGetShipperItem != null)
				this.MockGetShipperItem(this, e);
		}

		/// <summary>
		/// The event for the Persist method
		/// </summary>
		public event EventHandler<OrderPersistEventArgs> MockOrderPersist;

		/// <summary>
		/// Raises the OnMockPersist event
		/// </summary>
		protected virtual void OnMockOrderPersist(OrderPersistEventArgs e)
		{
			if (this.MockOrderPersist != null)
				this.MockOrderPersist(this, e);
		}

		/// <summary>
		/// The event for the Delete method
		/// </summary>
		public event EventHandler<OrderDeleteEventArgs> MockOrderDelete;

		/// <summary>
		/// Raises the OnMockDelete event
		/// </summary>
		protected virtual void OnMockOrderDelete(OrderDeleteEventArgs e)
		{
			if (this.MockOrderDelete != null)
				this.MockOrderDelete(this, e);
		}

		#endregion

	}
}
